layui.use(['jquery', 'layer', 'form'], function () {
    var $ = layui.jquery,
        layer = layui.layer,
        form = layui.form;
    //自定义验证规则
    form.verify({
        title: function (value) {
            if (value.length < 2) {
                return '用户名至少得2个字符啊';
            }
        },
        pass: [
            /^[\S]{6,12}$/,
            '密码必须6到12位，且不能出现空格'
        ],
    });

    var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
    //关闭iframe
    $('#submitBtn').click(function () {

        $.ajax({
            url: "/users/add/",
            type: "POST",
            async: "false",
            data: form.val('example'),
            success: function (data) {
                if (data.code === 0) {
                    parent.layer.close(index);
                    //成功后刷新父界面
                    window.parent.location.reload();
                } else {
                    parent.layer.msg(data.msg);
                }
            }
        });
    });
});